import unittest
from pygo1963.model.Vertex import Vertex, InvalidBoardVertexError


class VertexTest(unittest.TestCase):


    def test_valid_vertex(self):
        vertex = Vertex.from_string('a1')
        
        self.assertEquals(vertex.x, 0)
        self.assertEquals(vertex.y, 0)
        
        vertex = Vertex.from_string('L15')
        
        self.assertEquals(vertex.x, 10)
        self.assertEquals(vertex.y, 14)
        
        vertex = Vertex.from_string('Z25')
        
        self.assertEquals(vertex.x, 24)
        self.assertEquals(vertex.y, 24)
        
    def test_illegal_vertex(self):
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, 'A26')
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, 'i3')
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, 'I3')
    
    def test_invalid_vertex(self):
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, 'a 1')
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, '1a')
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, '')
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, 'a')
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, '1')
        self.assertRaises(InvalidBoardVertexError, Vertex.from_string, 'xcvc')

    
    def test_str(self):
        v1 = Vertex.from_string('a1')
        v2 = Vertex.from_string(' A1 ')
        
        self.assertEquals(str(v1), 'a1')
        self.assertEquals(str(v2), 'a1')
    
    def test_equals(self):
        v1 = Vertex.from_string('a1')
        v2 = Vertex.from_string(' A1 ')
        
        self.assertEquals(v1, v2)
        
        v3 = Vertex.from_string('a2')
        v4 = Vertex.from_string('b1')
        
        self.assertNotEquals(v1, v3)
        self.assertNotEquals(v1, v4)
        
    def test_from_coord(self):
        self.assertEquals(Vertex.from_string('a1'), Vertex(0, 0))
        self.assertEquals(Vertex.from_string('l15'), Vertex(10, 14))
        self.assertEquals(Vertex.from_string('z25'), Vertex(24, 24))

    def test_hash(self):
        self.assertEqual(Vertex(1, 5), Vertex(1, 5))
        self.assertNotEquals(Vertex(1, 0), Vertex(0, 1))
    
    def test_pass(self):
        self.assertEquals(Vertex.PASS(), Vertex.PASS())
        self.assertNotEquals(Vertex(-1, -1), Vertex.PASS())
        
        self.assertEquals(Vertex.PASS(), Vertex.from_string('pass'))

if __name__ == "__main__":
    unittest.main()